package com.gzsxy.lesson01;

import java.io.File;
import java.util.ArrayList;

public class FileController {


    File file;
    ArrayList<File> filelist;

    public FileController(File file) {
        this.file = file;
        this.filelist = new ArrayList<>();
    }


    //获取所有的文件
    public void searchFile() {
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isDirectory()) {
                file = file1;
                searchFile();
            } else {
                filelist.add(file1);
            }
        }
    }

    public ArrayList<File> getAllFile() {
        searchFile();
        return filelist;
    }


    public static void main(String[] args) {
        String folder = "D:\\dirA";
        File file1 = new File(folder);
        FileController fileController = new FileController(file1);
//        System.out.println(fileController.countFile());
        System.out.println(fileController.getAllFile());
    }

}
